<%= render :partial => 'admin/shared/product_sub_menu' %>

<div class='toolbar'>
  <ul class='actions'>
	<% product_counts=products_count_checking(current_user)%>
	<%if product_counts == true%>
    <li id="new_product_link">
      <%= button_link_to t("new_product"), new_object_url, {:remote => true, :icon => 'add', :id => 'admin_new_product'} %>
    </li>
		<%end%>
  </ul>
  <br class='clear' />
</div>

<h1><%= "#{t("actions.listing")} #{t("products")}" %></h1>

<div id="new_product"></div>

<table class="index" id='listing_products'>
  <tr data-hook="admin_products_index_headers">
    <th><%= t("sku") %></th>
    <th><%= sort_link @search,:name, t("name"), {}, {:title => 'admin_products_listing_name_title'} %></th>
    <th><%= sort_link @search,:master_price, t("master_price") %></th>
    <th data-hook="admin_products_index_header_actions"></th>
  </tr>
<% @collection.each do |product| %>
  <tr <%= 'style="color:red;"' if product.deleted? %> id="<%= dom_id product %>" data-hook="admin_products_index_rows">
    <td><%= product.sku %></td>
    <td><%= product.name %></td>
    <td><%= product.price %></td>
    <td class="actions" data-hook="admin_products_index_row_actions">
      <%= link_to_edit product, :class => 'edit' unless product.deleted?  %>
      &nbsp;
			
	<%if product_counts == true%>
		<%= link_to_clone product, :class => 'clone' %>
	<%end%>
      &nbsp;
      <%= link_to_delete product unless product.deleted?  %>
    </td>
  </tr>
<% end %>
</table>
<%= will_paginate(:previous_label => "&#171; #{t('previous')}", :next_label => "#{t('next')} &#187;") %>

<% content_for :sidebar do %>
  <div data-hook="admin_products_sidebar">
    <%= form_for [:admin, @search] do |f| %>
      <div class="box">
        <h3><%= t(:search) %></h3>

        <%- locals = {:f => f} %>
        <div data-hook="admin_products_index_search">
          <p>
            <%= f.label :name_contains, t("name") %><br />
            <%= f.text_field :name_contains, :size => 15 %>
          </p>
          <p>
            <%= f.label :variants_including_master_sku_contains, t("sku") %><br />
            <%= f.text_field :variants_including_master_sku_contains, :size => 15 %>
          </p>
          <p>
            <%= f.label :deleted_at_is_null, t("show_deleted") %><br />
            <%= f.check_box :deleted_at_is_null, {:checked => params[:search][:deleted_at_is_null].blank?}, "", "1" %>
          </p>
        </div>

        <div data-hook="admin_products_index_search_buttons">
          <p class="form-buttons">
            <%= button t("search") %>
          </p>
        </div>
      </div>
    <% end %>
  </div>
<% end %>

